package com.jy.wms.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jy.wms.common.annotions.BaseServiceDescribe;
import com.jy.wms.common.base.BaseService;
import com.jy.wms.common.base.ServiceException;
import com.jy.wms.dao.WmsReservoirUtilizationMapper;
import com.jy.wms.pojo.WmsReservoirUtilization;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class WmsReservoirUtilizationService extends BaseService<WmsReservoirUtilizationMapper,WmsReservoirUtilization> {
    @Resource
    private WmsReservoirUtilizationMapper wmsReservoirUtilizationMapper;

    /**
     * 分页查询
     * @param entity 实体
     * */
    @BaseServiceDescribe(moduleName = "库位使用率报表", btnName = "分页查询")
    public Page<WmsReservoirUtilization> baseHarvestPage(WmsReservoirUtilization entity) throws Exception {
        Page<WmsReservoirUtilization> list = null;
        try {
            PageHelper.startPage(entity.getPage(), entity.getRows());
            list=(Page<WmsReservoirUtilization>) dao.baseSelectPage(entity);//分页查询
            for(WmsReservoirUtilization wmsReservoirUtilization:list){
                //库位数量
                int kw=dao.getKwsl(wmsReservoirUtilization.getKqmc());
                //已使用库位
                int ysykw=dao.getYslkw(wmsReservoirUtilization.getKqmc());
                //空闲库位
                int kxkw=dao.getKxkw(wmsReservoirUtilization.getKqmc());
                wmsReservoirUtilization.setNums(kw);
                wmsReservoirUtilization.setYzykw(ysykw);
                wmsReservoirUtilization.setWzykw(kxkw);
            }
            return list;
        } catch (Exception e) {
            throw new ServiceException("库位使用率报表分页查询失败", e);
        }
    }
    /**
     * 导出
     * */
    @BaseServiceDescribe(moduleName = "导出报表",btnName = "导出库位使用率报表")
    public List<WmsReservoirUtilization> exportWmsReservoirUtilization(WmsReservoirUtilization entity){
        List<WmsReservoirUtilization> list=dao.exportWmsReservoirUtilization(entity);
        for(WmsReservoirUtilization wmsReservoirUtilization:list){
            //库位数量
            int kw=dao.getKwsl(wmsReservoirUtilization.getKqmc());
            //已使用库位
            int ysykw=dao.getYslkw(wmsReservoirUtilization.getKqmc());
            //空闲库位
            int kxkw=dao.getKxkw(wmsReservoirUtilization.getKqmc());
            wmsReservoirUtilization.setNums(kw);
            wmsReservoirUtilization.setYzykw(ysykw);
            wmsReservoirUtilization.setWzykw(kxkw);
        }
        return list;
    }
}
